package com.bul.controller;

import com.bul.domain.User;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Controller
//@RequestMapping("/user")
public class UserController {
    //restful入门；提交方式：查询get,新增post,修改普通,删除delete
    @RequestMapping(value = "/users",method = RequestMethod.POST)
    @ResponseBody
    public String save(){
        System.out.println("user save...");
        return "{'module':'user save...'}";
    }

    @RequestMapping(value = "/users/{id}" ,method = RequestMethod.DELETE)
    @ResponseBody
    //PathVariable设定请求参数，说明变量来自于路径，路径来自value上的{id}
    public String delete(@PathVariable Integer id){
        System.out.println("user delete..."+id);
        return "{'module':'user delete...'}";
    }

    //数组
    @RequestMapping("/arrayParam")
    @ResponseBody
    public String arrayParam(String[] likes){
        System.out.println("user likes..."+ Arrays.toString(likes));
        return "{'module':'array param...'}";
    }

    //集合
    @RequestMapping("/listParam")
    @ResponseBody
    public String listParam(@RequestParam List<String> likes){
        System.out.println("user likes..."+likes);
        return "{'module':'list param...'}";
    }
    //json格式
    @RequestMapping("/listParamForJson")
    @ResponseBody
    public String listParamForJson(@RequestBody List<String> likes){
        System.out.println("user json..."+likes);
        return "{'module':'user jsonlist...'}";
    }
    //pojo参数：json格式
    @RequestMapping("/pojoParamForJson")
    @ResponseBody
    public String pojoParamForJson(@RequestBody User user){
        System.out.println("user json..."+user);
        return "{'module':'user jsonUser...'}";
    }
    //集合参数，json格式
    @RequestMapping("/listpojoParamForJson")
    @ResponseBody
    public String listpojoParamForJson(@RequestBody List<User>  user){
        System.out.println("listuser json..."+user);
        return "{'module':'listuser jsonUser...'}";
    }

    //日期型参数
    @RequestMapping("/dateParam")
    @ResponseBody
    //DateTimeFormat类型转换器指定格式
    public String dateParam(Date date,
                            @DateTimeFormat(pattern = "yyyy-MM-dd") Date date1,
                            @DateTimeFormat(pattern = "yyyy/MM/dd HH:mm:ss") Date date2){
        System.out.println("dataParam..."+date);
        System.out.println("dataParam...yyyy-MM-dd"+date1);
        System.out.println("dataParam...yyyy/MM/dd HH:mm:ss"+date2);
        return "{'date':'dataParam...'}";
    }

}
